﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Trigger_Second2 : MonoBehaviour
{
    GameObject player = null;
    public GameObject door;
    public GameObject showBall;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if(player!=null&&Input.GetKeyUp(KeyCode.E))
        {
            door.GetComponent<Animator>().SetBool("Open", true);
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag.Equals("Player"))
        {
            player = other.gameObject;
            if (other.GetComponent<Tools>().isHasKeyRoom2)
            {
                showBall.GetComponent<BindShowText>().setShowText("按“E”键开门");
                showBall.GetComponent<BindShowText>().showShowText();

            }
            else
            {
                showBall.GetComponent<BindShowText>().setShowText("你没有钥匙！");
                showBall.GetComponent<BindShowText>().showShowText();
            }
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.tag.Equals("Player"))
        {
            showBall.GetComponent<BindShowText>().setShowText("");
            showBall.GetComponent<BindShowText>().showShowText();
            door.GetComponent<Animator>().SetBool("Open", false);
            player = null;
        }
    }
}
